#include <SnakeLib/Problem.h>

#include "MySolver.h"

using namespace snake;
  


EDirection MySolver::Solve(const snake::Problem &problem)
  {  
  auto board = problem.GetBoard();
  
  SnakeInfo snake_info = GetSnakeInfo(board);
  ECellContents next_cell;
  
  switch (snake_info.m_direction)
    {
    case EDirection::DOWN:
      next_cell = board.GetCell(snake_info.m_head_coord.first, snake_info.m_head_coord.second+1);
      if (next_cell == ECellContents::CELL_WALL)
        return LEFT;
      break;
    case EDirection::LEFT:
      next_cell = board.GetCell(snake_info.m_head_coord.first-1, snake_info.m_head_coord.second);
      if (next_cell == ECellContents::CELL_WALL)
        return EDirection::UP;
      break;

    case EDirection::RIGHT:
      next_cell = board.GetCell(snake_info.m_head_coord.first+1, snake_info.m_head_coord.second);
      if (next_cell == ECellContents::CELL_WALL)
        return EDirection::DOWN;
      break;

    case EDirection::UP:
      next_cell = board.GetCell(snake_info.m_head_coord.first, snake_info.m_head_coord.second-1);
      if (next_cell == ECellContents::CELL_WALL)
        return EDirection::RIGHT;
      break;
    default:
      throw std::logic_error("unsupported case EDirection");
    }
  return UP;
  }

